package second.group.bering.parking_system

import second.group.bering.parking_system.model.Car
import spock.lang.Specification
import spock.lang.Unroll;
/**
 *
 * ParkTest
 *
 * @author Burgess Li, Thomas Chen
 * @date 8/23/2018 2:20 PM
 * @version 1.0
 *
 */
class ParkTest extends Specification {

    @Unroll
    def 'should return parking result: #PARKING_RESULT when input car: #CAR_NUMBER, park size: #PARK_SIZE, current available location: #CURRENT_AVAILABLE_LOCATION'() {

        given:
        Park parking = new Park(size: PARK_SIZE)
        Car car = CAR_NUMBER ? new Car(number: CAR_NUMBER) : null

        expect:
        parking.parking(car) == PARKING_RESULT
        parking.availableLocation() == CURRENT_AVAILABLE_LOCATION

        where:
        CAR_NUMBER   |   PARK_SIZE    |   PARKING_RESULT    |   CURRENT_AVAILABLE_LOCATION
        'A123'       |   1            |   true              |   0
        'A123'       |   0            |   false             |   0
        null         |   1            |   false             |   1
        ''           |   1            |   false             |   1

    }

    @Unroll
    def 'should return pickup result: #PICKUP_CAR_NUMBER when pickup car number: #CAR_NUMBER, park contains car numbers: #CONTAINS_CAR_NUMBERS, current available location: #CURRENT_AVAILABLE_LOCATION'(){

        given:
        Park parking = new Park(size: CONTAINS_CAR_NUMBERS.size())
        CONTAINS_CAR_NUMBERS.each { parking.parking(new Car(number: it)) }

        expect:
        parking.pickup(CAR_NUMBER)?.number == PICKUP_CAR_NUMBER
        parking.availableLocation() == CURRENT_AVAILABLE_LOCATION

        where:
        CONTAINS_CAR_NUMBERS    |   CAR_NUMBER   |  PICKUP_CAR_NUMBER   |   CURRENT_AVAILABLE_LOCATION
        ['A123']                |   'A123'       |  'A123'              |   1
        ['A123']                |   'A999'       |  null                |   0
        ['A123', 'A456']        |   'A456'       |  'A456'              |   1

    }

}
